<?php
/**
 * common model file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/10/26
 * Time: 10:47
 */

namespace HiCommon\Model;

class StoreOrderGoods extends Base
{

    protected $table = 'store_order_goods';

    protected $guarded = [];

    //public $timestamps = false;

    /**
     * 应该被调整为日期的属性
     *
     * @var array
     */
    protected $dates = [
    ];

    /**
     *  关联产品表
     **/
    public function goods_product()
    {
        return $this->belongsTo(GoodsProduct::class, 'goods_product_id', 'id')
            ->select('id','goods_id','goods_specs_id','price','integral','stock','sell','pic','created_at');
    }

    /**
     *  关联产品表
     **/
    public function goods()
    {
        return $this->belongsTo(Goods::class, 'goods_id')->select('id','pic_url','name');
    }

    /**
     * 商品退货退货状态
     */
    public function goods_refund_status()
    {
        return $this->hasOne(StoreOrderRefundGoods::class, 'store_order_goods_id','id')
            ->with(['order_refund'])->orderBy('id', 'desc')
            ->select('id','store_order_refund_id','store_order_goods_id');

    }

    /**
     * 获取图片可用链接
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getGoodsPicAttribute($value)
    {
        $arr_data = [
            'src' => $value,
            'full_src' => oss_full_url($value),
        ];
        return $arr_data;
    }

    /**
     * 扩展信息
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getExtendAttribute()
    {
        $s_created_at = $this->created_at;
        $arr_data = [
            'created_at' => ymd_friendly_date($s_created_at),
        ];

        return $arr_data;
    }


}